package com.example.spring_start.controller;

import com.example.pojo.banner;
import com.example.req.bannerReq;
import com.example.req.bannerSaveReq;
import com.example.resp.CommonResp;
import com.example.resp.PageResp;
import com.example.spring_start.service.bannerService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/banner")
@CrossOrigin(origins = "http://localhost:8015")
public class bannerController {
    @Resource
    bannerService bannerService;

    @GetMapping("/getbannerList")
    public CommonResp getbannerList(bannerReq bannerReq){
        CommonResp<PageResp<banner>> resp = new CommonResp<>();
        PageResp<banner> list = bannerService.getbannerList(bannerReq);
        resp.setContent(list);
        return resp;
    }

    @PostMapping("/addbanner")
    public CommonResp addbanner(@RequestBody bannerSaveReq req){
        CommonResp<banner> resp = new CommonResp<>();
        bannerService.addbanner(req);
        return resp;
    }

    @DeleteMapping("/deletebanner")
    public CommonResp deletebanner(String bannerid){
        CommonResp<banner> resp = new CommonResp<>();
        bannerService.deletebanner(Long.parseLong(bannerid));
        return resp;
    }
}
